home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / editor / snmp_0_1.zip / snmp-0.1 / aka / snmp / StringUtil.java < prev    next >
Text File  |  1997-06-09  |  2KB  |  70 lines

  1. /*
  2. Snmp Library
  3. Copyright (C) 1997 Alex Kowalenko Associates Pty Ltd. All rights reserved.
  4.  
  5. This software maybe be free distributed, any any form, without fee, 
  6. but may not be modified in any way without express permission of 
  7. the directors of Alex Kowalenko Associates Pty Ltd. 
  8.  
  9. Alex Kowalenko Associates Pty Ltd makes no representations or
  10. warranties about the suitabililty of the software, not even the
  11. implied warranty of merchantability or fitness for any particular
  12. purpose.    
  13. */
  14.  
  15. /**
  16.  * This class has some useful static member functions.
  17.  * @version     $Id: StringUtil.java,v 1.2 1997/05/12 12:17:48 alex Exp $
  18.  * @author      Alex Kowalenko
  19.  */
  20.  
  21. package aka.snmp;
  22.  
  23. import java.util.*;
  24.  
  25. public class StringUtil {
  26.   
  27. /**
  28.  * Is a String a numeric constant?
  29.  */
  30.  
  31.   public static boolean isNumeric(String str) {
  32.       for(int i = 0; i < str.length(); i++)
  33.       if(!Character.isDigit(str.charAt(i)))
  34.           return false;
  35.       return true;
  36.   };
  37.  
  38. /**
  39.  * Provide a Hexdump of a ByteBuffer
  40.  */
  41.  
  42.   public static void Hexdump(ByteBuffer buffer) {
  43.       int size = buffer.size();
  44.       System.err.println("Buffer size : " + size);
  45.       System.err.println("--------------------------------------------------");
  46.       for(int i = 0; i < (size < 200 ? size : 200); i ++) {
  47.       System.err.print(Integer.toHexString((int) buffer.byteAt(i)));
  48.       if(buffer.byteAt(i) > 0x20 && buffer.byteAt(i) < 0x80)
  49.           System.err.print("[" + (char) buffer.byteAt(i) + "] ");
  50.       else
  51.           System.err.print("[ ] ");
  52.       if((i % 16 ) == 15)
  53.           System.err.println("");
  54.       };
  55.       System.err.println("");
  56.       return;
  57.   };
  58.  
  59. /**
  60.  * Test harness
  61.  */
  62.  
  63.   public static void main(String args[]) {
  64.       System.out.println("Is numeric dog? : " + isNumeric("dog"));
  65.       System.out.println("Is numeric 1? : " + isNumeric("1"));
  66.       // Hexdump(new StringBuffer("Holden Caulfield, Catcher in the Rye"));
  67.   };
  68.  
  69. };
  70.